<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Session;
use DB;

class LoginController extends Controller
{
    public function login()
    {
        return view('home.login.login');
    }
    public function dologin(Request $request)
    {
        $data = $request -> only('phone','password');
        $code = $request -> captcha;
        $captcha = Session::get('milkcaptcha');
        if($code == $captcha){
            $data = DB::table('user') -> where('phone',$data['phone']) -> first();
            if(empty($data)){
                echo '用户名或密码错误';
            }else{
                session(['user' => $data]);
                return redirect('/home/index/index');
            }
        }else{
            return back() -> with(['info' => '验证码错误']);
        }
    }
    //退出登录
    public function logout()
    {
        //清除session
        session() -> forget('user');
        return redirect('/home/login/login') -> with(['info' => '退出成功']);
    }
    public function indexed(){
        // $data = $request->session()->all();

        return view('/home/index/indexed');
    }
}
